#include "weaveinstructionview.h"
#include "ui_weaveinstructionview.h"
#include <QDebug>

WeaveInstructionView::WeaveInstructionView(int styleId,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WeaveInstructionView)
{
    ui->setupUi(this);
    setGeometry(5,50,451,544);
    initialDisplayStyle(styleId);

}

void WeaveInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->note_GBox->hide();
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

WeaveInstructionView::~WeaveInstructionView()
{
    delete ui;
}


void WeaveInstructionView::getInput(WeaveInstruction &instructionParaOut)
{
    instructionParaOut.weaveConditionIndex=ui->comboBox_conditionIndex->currentIndex();
    instructionParaOut.weaveType=E_WEAVE_TYPE_COMMON;
    instructionParaOut.comment=ui->note_lineEdit->text();



}
void WeaveInstructionView::updateView()
{
    qDebug() << "instructionPara.weavePropertyIndex:" <<instructionPara.weavePropertyIndex;
    ui->comboBox_conditionIndex->setCurrentIndex(instructionPara.weaveConditionIndex);


    ui->note_lineEdit->setText(instructionPara.comment);

}
void WeaveInstructionView::changeLanguage(int language)
{
    //TODO
}

void WeaveInstructionView::finishEditInstruction(WeaveInstruction instructionParaIn, QString &instructionStrOut)
{
    instructionStrOut.clear();
       instructionStrOut="Weave ";
       instructionStrOut+=" [";
       switch (instructionParaIn.weaveType) {
       case E_WEAVE_TYPE_COMMON:
           instructionStrOut+=QString::number(instructionParaIn.weaveConditionIndex)+"]";

           break;
       case E_WEAVE_TYPE_HZ:

           instructionStrOut+=QString::number(instructionParaIn.weaveHz)+"Hz,"
                          +QString::number(instructionParaIn.weaveAmplitude)+"mm,"
                          +QString::number(instructionParaIn.weaveLeftStay,10,2)+"sec,"
                          +QString::number(instructionParaIn.weaveRightStay,10,2)+"sec]";
           break;
       default:
           break;
       }
      instructionStrOut+=";//"+instructionParaIn.comment;
}




void WeaveInstructionView::on_button_editCondition_clicked()
{
    emit showWeaveConditionView_signal();
}



void WeaveInstructionView::on_save_Btn_clicked()
{
    getInput(instructionPara);
    finishEditInstruction(instructionPara,instructionStr);
//    emit finishEditInstructionSignal();
    emit saveInstructionSignal(instructionStr);

}

void WeaveInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->setText("");

}
